package voja.android.vwidget;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.widget.RemoteViews;

public class ClockService extends Service {
	private BroadcastReceiver receiver = new BroadcastReceiver(){
		public void onReceive(Context context, Intent intent){
			String action = intent.getAction();
			if (action.equals(Intent.ACTION_TIME_TICK)){
				RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget);
				VWidgetProvider.updateWidget(context, updateViews);
				
				android.content.ComponentName myComponentName = new android.content.ComponentName(context, VWidgetProvider.class);
				android.appwidget.AppWidgetManager manager = android.appwidget.AppWidgetManager.getInstance(context);
				manager.updateAppWidget(myComponentName, updateViews);
			}
		}
	};
	
	public IBinder onBind(Intent arg0) {
		return null;
	}
	
	public void onCreate() {
		super.onCreate();
		
		android.content.IntentFilter intentFilter = new android.content.IntentFilter();
		intentFilter.addAction(Intent.ACTION_TIME_TICK);
		registerReceiver(receiver, intentFilter);
	}
	
	public void onDestroy() {
		super.onDestroy();
		unregisterReceiver(receiver);
	}
}
